<?php
namespace app\common\model;
use think\Model;
use think\Validate;
use app\common\controller\Tools;
class Consult extends Model
{
	protected $table = 'consult';
	protected $pk = 'consult_id';


	public static function getConsults($pagesize = 2)
	{
		$where = [
			'a.consult_type' => 1,
			'a.consult_is_delete' => 0,
			'a.consult_to_person' => session('merchant.merchant_id')
		]; 
		$data = Consult::alias('a')->field('a.*,b.nickname')
			->join('user b', 'a.consult_from_person=b.user_id')
			->where('consult_to_person', session('merchant.merchant_id'))
			->paginate($pagesize);
		// $data = Consult::alias('a')
		// 		->field('a.consult_id,a.consult_from_person,a.consult_content,a.consult_create_time,b.nickname')
		// 		->join('user b', 'a.consult_from_person=b.user_id', 'left')
		// 		// ->join('goods_order c', 'b.user_id=c.order_user_id')
		// 		->where($where)->paginate($pagesize);
		// $data = Consult::alias('a')
		// 		->field('a.consult_id,a.consult_from_person,a.consult_content,a.consult_create_time,b.nickname,c.order_order_sn')
		// 		->join('user b', 'a.consult_from_person=b.user_id', 'left')
		// 		->join('goods_order c', 'b.user_id=c.order_user_id')
		// 		->where($where)->paginate($pagesize);
		// foreach($data as $k => &$v)
		// {
		// 	$v['consult_create_time'] = $v['consult_create_time'];
		// }
		return $data;
	}
	
	public static function GetMessageConsults($pagesize = 2)
	{
		$where = [
			'a.consult_type' => 1,
			'a.consult_is_delete' => 0,
			'a.consult_to_person' => session('merchant.merchant_id')
		]; 
		$data = db('message_consult')::alias('a')
			->join('user b', 'a.consult_from_person=b.user_id')
			->where('consult_to_person', session('merchant.merchant_id'))
			->paginate($pagesize);
	}
	
	
}